// 生产环境的webpack配置文件

const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
module.exports = {
  mode: "production",
  entry: path.resolve(process.cwd(), "./src/index.js"), //入口文件
  output: {
    path: path.resolve(process.cwd(), "./dist"),
    filename: "[name].js",
    publicPath: "/",
  },
  module: {
    rules: [
      {
        test: /\.html$/i,
        loader: "html-loader",
      },
      {
        test: /\.ejs$/,
        loader: "ejs-loader",
        options: {
          variable: "data", // 可以在模块当中使用data进行数据处理
        },
      },
    ],
  },
  resolve: {
    alias: {
      "@": path.resolve(process.cwd(), "src/views"), // @ 符号  等同于 path.resolve(process.cwd(), "src/views")
    },
  },
  plugins: [
    new HtmlWebpackPlugin({
      title: "admin",
      filename: "index.html",
      template: "./public/index.html",
    }),
    new CopyWebpackPlugin({
      patterns: [
        {
          from: "public",
          to: "./",
          globOptions: {
            ignore: ["**/index.html"],
          }, //这里是为了在copy目录的时候排除index.html，只copy图标
        },
        {
          from: "./src/static",
          to: "./",
        },
      ],
    }),
  ],
};
